<template>
  <div class="update">
       <group label-width="5em" title="更改密码">
            <cell-box class="change">
                <h1>更改密码</h1>
            </cell-box>
            <x-input title="用户名" placeholder="请输入用户名" v-model="user"></x-input>
            <x-input title="原始密码" type="password" placeholder="请输入原始密码" v-model="psw"></x-input>
            <x-input title="新密码" type="password" placeholder="请输入新的密码" v-model="psw1"></x-input>
            <cell>
                <router-link :to="{name:'Reg'}" class="login">没有帐号，我要注册</router-link>
            </cell>
            <x-button type="primary"  class="button" @click.native="changeSub()">提交</x-button>
        </group>
  </div>
</template>
<script>
 import { CellBox,Group,XInput,Cell,XButton } from 'vux';
 import {update} from '../service/update'
export default {
  name: 'Update',
  components:{
      CellBox,
      Group,
      XInput,
      Cell,
      XButton
  },
  data(){
      return {
         user:'',
         psw:'',
         psw1:''
      }
  },
  methods:{
      changeSub(){
          if(this.psw == ''){
              alert('请输入原始密码')
          }
          if(this.psw1 == ''){
              alert('请输入新密码')
          }
          update({
            user:this.user,
            psw:this.psw,
            psw1:this.psw1,
          }).then((res) => {
              console.log(res)
             if(res.data.msg == '修改成功'){
                  this.$router.push({
                  name: 'Login'
              })
             }
          })
      }
  }
}
</script>
<style>
.change{
    height: 150px;
}
h1{
    width: 100%;
    text-align: center;
}
</style>


